import wx
import wx.grid

from gui.panels.panel_backtest import BacktestPanel
from gui.panels.panel_data import PanelData
from gui.widgets.widget_web import WebPanel


class RightNotebook(wx.Notebook):
    def __init__(self, parent):
        super(RightNotebook, self).__init__(parent)

        # 创建策略回测界面
        self.backtest_panel = BacktestPanel(self)
        self.AddPage(self.backtest_panel, "本地策略回测")

        #创建历史数据页面
        #self.history_panel = PanelData(self)
        #history_label = wx.StaticText(self.history_panel, label="历史数据查询")
        #history_sizer = wx.BoxSizer(wx.VERTICAL)
        #history_sizer.Add(history_label, 0, wx.ALL, 10)
        #self.history_panel.SetSizer(history_sizer)
        #self.AddPage(self.history_panel, "akshare数据下载")

        # # 创建技术分析页面
        # self.technical_panel = wx.Panel(self)
        # technical_label = wx.StaticText(self.technical_panel, label="技术分析图表")
        # technical_sizer = wx.BoxSizer(wx.VERTICAL)
        # technical_sizer.Add(technical_label, 0, wx.ALL, 10)
        # self.technical_panel.SetSizer(technical_sizer)
        # self.AddPage(self.technical_panel, "技术分析")


        # web2 = WebPanel(self)
        # self.AddPage(web2, "智能投研子系统", True)
        # web2.show_url("http://localhost:8501")
        self.SetSelection(0)




class MarketDataPanel(wx.Panel):
    def __init__(self, parent):
        super(MarketDataPanel, self).__init__(parent)

        # 创建数据表格
        self.grid = wx.grid.Grid(self)
        self.grid.CreateGrid(20, 5)

        # 设置列标签
        columns = ["时间", "代码", "名称", "最新价", "成交量"]
        for col, label in enumerate(columns):
            self.grid.SetColLabelValue(col, label)
            self.grid.SetColSize(col, 100)

        # 添加示例数据
        self._add_sample_data()

        # 主布局
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.grid, 1, wx.EXPAND)
        self.SetSizer(sizer)

    def _add_sample_data(self):
        """添加示例市场数据"""
        import random
        from datetime import datetime, timedelta

        now = datetime.now()
        symbols = ["600000.SH", "000001.SZ", "AAPL", "MSFT", "GOOGL"]

        for row in range(self.grid.GetNumberRows()):
            time = now - timedelta(minutes=row)
            symbol = symbols[row % len(symbols)]
            price = round(100 + random.random() * 10, 2)
            volume = random.randint(1000, 100000)

            self.grid.SetCellValue(row, 0, time.strftime("%H:%M:%S"))
            self.grid.SetCellValue(row, 1, symbol)
            self.grid.SetCellValue(row, 2, f"股票{row + 1}")
            self.grid.SetCellValue(row, 3, str(price))
            self.grid.SetCellValue(row, 4, str(volume))